import { createRouter, createWebHistory } from 'vue-router'
import route from './route'
import * as names from './name'

const router = createRouter({
  routes: route.routes,
  history: createWebHistory(import.meta.env.BASE_URL),
  scrollBehavior(to, from, savedPosition) {
    // 始终滚动到顶部
    return { top: 0 }
  },
})

router.beforeEach((to, from) => {
  // debugger
  // if () {
  // }
})

/**
 * 前往frame页
 *
 * @export
 */
export function goFrameRouter() {
  router.push({
    name: names.FRAME,
  })
}

export function goLoginRouter() {
  router.push({
    name: names.LOGIN,
  })
}

export default router
